<template>
	<view class="page">
		<!-- 内容 -->
		<view class="content">
			<view class="title">
				法人信息
			</view>
			<view class="prompt">
				上传身份证照片，更新法人信息
			</view>
			<view style="display: flex; justify-content: space-between; padding: 20rpx;">
				<upload-image size="small" type="front" @uploaded="uploadedCardFront"></upload-image>
				<upload-image size="small" type="back" @uploaded="uploadedCardBack"></upload-image>
			</view>
			<view class="fui-wrap">
				<fui-form ref="FormRef" top="0" :model="formData">
					<fui-form-item label="法人姓名" labelWeight="600" labelWidth="200" :left="0" labelSize="28" prop="name">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入法人姓名"
							v-model="formData.name"></fui-input>
					</fui-form-item>
					<fui-form-item label="法人身份证号" labelWeight="600" labelWidth="200" :left="0" labelSize="28"
						prop="idcode">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]"
							placeholder="请输入法人身份证号" v-model="formData.idcode"></fui-input>
					</fui-form-item>
					<fui-form-item label="法人联系方式" labelWeight="600" :left="0" labelWidth="200" labelSize="28"
						prop="phone">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]"
							placeholder="请输入法人联系方式" v-model="formData.phone"></fui-input>
					</fui-form-item>
				</fui-form>
				<view class="login-agreement">
					<fui-label>
						<fui-checkbox :scaleRatio="0.6" @change="change"></fui-checkbox>
						<fui-text text="负责人与法人为同一人" size="24" color="var(--fui-color-link)"></fui-text>
					</fui-label>
				</view>
			</view>
			<!-- 底部按钮 -->
			<view class="btn">
				<fui-button :disabled="false" disabledBackground="#DFDFDF" borderColor="var(--fui-color-primary)" width="312rpx"
					height="78rpx" background="#FFFFFF" @click="cancellation" color="var(--fui-color-primary)">取消</fui-button>
				<fui-button :disabled="false" width="312rpx" height="78rpx" disabledBackground="#DFDFDF"
					background="var(--fui-color-primary)" @click="toshim">实名认证</fui-button>
			</view>
			<fui-toast ref="toast">
				<view class="fui-toast__custom">
					<view class="toast">
						<image src="../../../static/images/error.png" mode=""></image>
					</view>
					<view class="fui-toast__txt">您上传的营业执照上的法人姓名</view>
					<view class="fui-toast__txt">
						与身份证上姓名不一致，请重新提交！
					</view>
				</view>
			</fui-toast>
		</view>
	</view>
</template>

<script setup>
	import uploadImage from '@/components/upload/image'
	import SystemApi from '@/api/system.js'
	import staffApi from '@/api/staff.js'
	import {
		ref,
		inject
	} from 'vue'
	const modal = inject('$modal')
	const FormRef = ref(null)
	const checked = ref(false)
	const toast = ref(null)
	const businessLicense = uni.getStorageSync('editbusinessLicense')
	const rules = ref([{
		name: "name",
		rule: ["required"],
		msg: ["请输入法人姓名"]
	}, {
		name: "idcode",
		rule: ["required", "isIdCard"],
		msg: ["请输入法人身份证号", "请输入正常法人身份证号"]
	}, {
		name: "phone",
		rule: ["required", "isMobile"],
		msg: ["请输入法人联系方式", "请输入正确的手机号码"]
	}])
	const formData = ref({
		name: '',
		idcode: '',
		phone: ''
	})
	// const submitform = {
	// 	"name": businessLicense.corporatename, //公司名称
	// 	"creditCode": businessLicense.code, //信用代码
	// 	"corporationName": formData.value.name, //法人姓名
	// 	"corporationPhone": formData.phone, //法人手机号
	// 	"corporationIdCard": "123", //法人身份证号
	// 	"corporationFaceCheck": "Y", //法人人脸识别状态
	// 	"address": "admin", //地址
	// 	"description": "3333333", // 公司描述
	// 	"idcFront": "http://172.18.1.56:48080/admin-api/infra/file/4/get/9014c1e5f9d2a65053f92495f29acf03fc5e65cb948785fff314918589d33f09.png", //法人身份证正面
	// 	"idcBack": "http://172.18.1.56:48080/admin-api/infra/file/4/get/97a07f3bb68247aa0dfaf3ce37012891168d5abefb237ee15626d7b55e1be6d6.png", //法人身份证反面
	// 	"businessLicense": "http://172.18.1.56:48080/admin-api/infra/file/4/get/d820385b7d52ad2af936bee317d58d6448424c1df6c0fece02b49f07322b8b97.png", //营业执照
	// 	"isSamePerson": "N", //法人与负责人是否是同一人  N 否  Y是
	// }
	// 身份证正面上传
	const uploadedCardFront = async (e) => {
		if (e[0]) {
			const res = await SystemApi.uploadidcard({
				imageUrl: e[0]
			})
			formData.value.idcFront = e[0]
			if (res.code == 0) {
				let obj = JSON.parse(res.data)
				formData.value.name = obj['姓名']
				formData.value.idcode = obj['公民身份号码']
			}
		}
	}
	// 身份证反面上传
	const uploadedCardBack = (e) => {
		console.log('uploadedCardBack', e)
	}
	//取消
	const cancellation = (() => {
		uni.navigateBack({
			delta: 1
		})
	})
	const change = ((e) => {
		checked.value = e
	})
	//下一步
	const toshim = (async () => {
		//判断是否和上个法人一致
		// if (businessLicense.name != formData.value.name) {
		// 	let obj = {}
		// 	toast.value.show(obj)
		// 	return
		// }
		const validRes = await FormRef.value.validator(formData.value, rules.value)
		if (validRes.isPassed) {
			// if (checked.value == true) {
			// 	const res = await staffApi.editStaff()
			// }
			uni.navigateTo({
				url: `./idAuthentication?checked=${checked.value}`
			})
		}
	})
</script>

<style lang="scss" scoped>
	.content {
		margin: 36rpx;

		.title {
			font-size: 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.login-agreement {
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			.fui-label__box {
				display: flex;
				align-items: center;

				.fui-checkbox__input {
					margin-right: 12rpx;
				}
			}
		}

		.prompt {
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-top: 20rpx;
		}

		::v-deep.fui-form__wrap-inner {
			padding: 0 !important;
		}

		// ::v-deep.fui-input__self {
		// 	font-weight: bold;
		// }
		::v-deep.uni-input-input {
			font-weight: bold;
		}

		.btn {
			padding-bottom: 118rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-top: 132rpx;
		}

		::v-deep.uni-textarea-textarea {
			font-weight: bold;
		}

		::v-deep.textarea-box .fui-form__wrap-inner {
			display: initial !important;
		}

		.fui-toast__custom {
			width: 594rpx;
			height: 352rpx;
			padding: 42rpx 18rpx 0 18rpx;
			box-sizing: border-box;

			.toast {
				width: 128rpx;
				height: 128rpx;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 50%;
				margin-bottom: 42rpx;

				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			.fui-toast__txt {
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
				text-align: center;
				padding-bottom: 8rpx;
			}

		}
	}
</style>